//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    typeFoods:[],

    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    
  },
  //事件处理函数
  ax(){
    let that=this;
    wx.request({
      url: 'http://t.yushu.im/v2/movie/in_theaters ',
      success: function (res) {
        console.log(res)
        if (res.statusCode === 200) {
          that.setData({
            typeFoods: res.data.subjects.slice(0,3)// 把请求过来的参数添加到空数组后面
          })
        }
        console.log(that.data.typeFoods);
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },
  onLoad: function () {
    this.ax();
    
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  dianji(){
    wx.navigateTo({
      url: "/pages/index/reyin/reyin",
    })
  },
  shangy(){
    wx.navigateTo({
      url: "/pages/index/shangyin/shangyin",
    })
  },
  top() {
    wx.navigateTo({
      url: "/pages/index/Top/top",
    })
  }
})
